package com.tairanchina.md.meeting.service.impl;

import com.tairanchina.md.meeting.dao.YearMeetingProgramMapperExt;
import com.tairanchina.md.meeting.dto.ProgramDto;
import com.tairanchina.md.meeting.entity.YearMeetingProgram;
import com.tairanchina.md.meeting.entity.YearMeetingProgramExample;
import com.tairanchina.md.meeting.service.YearMeetingProgramService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lxliuxuan on 2016/12/24.
 */
@Transactional
@Service
public class YearMeetingProgramServiceImpl implements YearMeetingProgramService{
	@Resource
    private YearMeetingProgramMapperExt programDao;


    @Override
    public ProgramDto findAllList(String order) {
        ProgramDto programDto = new ProgramDto();
        YearMeetingProgramExample example = new YearMeetingProgramExample();
        example.setOrderByClause(order);
        List<YearMeetingProgram> yearMeetingPrograms = programDao.selectByExample(example);
        programDto.setProgramNum(yearMeetingPrograms.size());
        programDto.setList(yearMeetingPrograms);
        return programDto;
    }

    @Override
    public YearMeetingProgram findProgramById(String id) {

        YearMeetingProgramExample example = new YearMeetingProgramExample();
        YearMeetingProgramExample.Criteria criteria = example.createCriteria();
        criteria.andProgramIdEqualTo(id);

        List<YearMeetingProgram> yearMeetingPrograms = programDao.selectByExample(example);
        if(yearMeetingPrograms != null && !yearMeetingPrograms.isEmpty()){
            return yearMeetingPrograms.get(0);
        }
        return null;
    }

    @Override
    public void updateProgram(YearMeetingProgram program) {
        YearMeetingProgramExample example = new YearMeetingProgramExample();
        YearMeetingProgramExample.Criteria criteria = example.createCriteria();
        criteria.andProgramIdEqualTo(program.getProgramId());
        programDao.updateByExampleSelective(program,example);
    }

    @Override
    public YearMeetingProgram findById(String id) {
        YearMeetingProgramExample example = new YearMeetingProgramExample();
        YearMeetingProgramExample.Criteria criteria = example.createCriteria();
        criteria.andProgramIdEqualTo(id);
        List<YearMeetingProgram> yearMeetingPrograms = programDao.selectByExample(example);
        if(yearMeetingPrograms != null && yearMeetingPrograms.size() >0){
            return yearMeetingPrograms.get(0);
        }
        return null;
    }
}
